// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    let doingWork= await db.collection("schdule").where({
        _openid:wxContext.OPENID,
        startTime:_.lt(new Date()),
        endTime:_.gt(new Date()),
        isDone:0
    }).get()
    let alreadyWork = await db.collection("schdule").where({
        _openid:wxContext.OPENID,
        isDone:1
    }).get()
    let allTask = await db.collection("schdule").where({
        _openid:wxContext.OPENID,
    }).get()
    console.log(new Date())
    return {
        code:200,
        doingWork:doingWork.data,
        alreadyWork:alreadyWork.data,
        allTask:allTask.data
    }
}